package com.yzf.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.yzf.dao.DocumentDao;
import com.yzf.entity.Document;
import com.yzf.entity.Employee;
import com.yzf.entity.Project;
import com.yzf.util.util.DateTimeUtil;
import com.yzf.util.util.StringUtil;
import com.yzf.util.web.ServletUtil;

public class NewDocument extends HttpServlet {

	
	private static final long serialVersionUID = 1L;


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		ServletUtil.forword(request, response, "new_document");
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setCharacterEncoding("UTF-8");
		
		HttpSession session=ServletUtil.getSession(request);
		Project project=(Project)session.getAttribute("project");
		//System.out.println(project.getId());
		
		Employee  em=(Employee)session.getAttribute("employee");
		//System.out.println(em.getId());
		String title=request.getParameter("title");
		String content=request.getParameter("content");
		
		
		Document document=new Document();
		document.setTitle(title);
		document.setContent(content);
		document.setId(StringUtil.getId());
		document.setCreatetime(DateTimeUtil.getNow());
		document.setProjectid(project.getId());
		document.setEmployeeid(em.getId());
		
		DocumentDao dao=new DocumentDao();
		dao.save(document);
		
		ServletUtil.redirect(response, "document.jspx");
	}

}
